<?php

namespace App\Admin\Controllers;

use App\Models\HotPhoneModel;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class HotPhoneController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '热线电话';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new HotPhoneModel());

        $grid->column('id', __('Id'));
        $grid->column('phone','电话');
        $grid->column('wx_img','微信二维码')->image('', 80, 80);
        $grid->column('email','邮箱');
        $grid->column('created_at', __('Created at'));

        $grid->column('updated_at', __('Updated at'));

        $grid->disableCreateButton();
        $grid->disableFilter();
        $grid->disableExport();

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(HotPhoneModel::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('phone','电话号码');
        $show->field('wx_img','微信二维码')->image('',160,160);
        $show->field('created_at', __('Created at'));
       // $show->field('email', __('Email'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new HotPhoneModel());

        $form->mobile('phone','手机热线');
        $form->image('wx_img','微信二维码')->move('images/' . date('Ymd')) ->uniqueName();
        $form->email('email','邮箱');

        return $form;
    }
}
